package View;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.HelperHtml;
import model.Tour;
import model.TourDAO;

/**
 * Servlet implementation class HomePage
 */
@WebServlet("/HomePage")
public class HomePage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
	TourDAO da;
    public HomePage() {
        super();
        da= new TourDAO();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("utf-8");
		response.getWriter().write(HelperHtml.getHtml(LoadData()));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	private String LoadData(){
		String st="";
		List<Tour> tours=da.DanhSachTour();
		for (Tour tour : tours) {
			st+="<article> "+
	            	"<img width=\"100\" height=\"80\" src=\"images/"+tour.getImage()+"\" id=\"logo\"/>"+
	                "<header> "+
	                    "<hgroup>"+ 
	                    "<h2><a href=\"DetailTour?MaTour="+tour.getMatour()+"\">"+tour.getTentour()+"</a></h2>"+ 
	                    "</hgroup>"+ 
	                "</header>"+ 
	                "<p><b>Giá: </b><strong class='price'>"+tour.getGia()+"</strong></p>"+ 
	                "<p>"+tour.getDiemkhoihanh()+"</p>"+
	                "<p><b>Thời gian: </b>"+tour.getThoigian()+"</p>"+
	            "</article>";
		}
		return st;
	}
}
